package model.siw
{
	import flash.events.ContextMenuEvent;
	import flash.events.Event;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	import mx.controls.Button;
	
	public class RuleFigure extends Button{
		
		
		private var _inputTran:TranFigure;
		
		private var _outputTran:TranFigure;
		
		private var _type:String;	
		
		private var _patternType:String;
		
		private var _position:int;
		
		private var _model:Rule;
		
		private var initSendItem:ContextMenuItem;
		
		private var sendItem:ContextMenuItem;
		
		private var initReceiveItem:ContextMenuItem;
		
		private var receiveItem:ContextMenuItem;
		
		public function RuleFigure(v:int, t:String)
		{
			
			super();
			
			this._position=v;
			this._type=t;
			createChildren();
			this.initialize();
			initContextMenu();
		
		}
		
		public function set model(v:Rule){
			this._model=v;
		}
		
		public function get model():Rule{
			return this._model;
		}
		
		public function set position(v:int){
			this._position=v;
		}
		
		public function get position():int{
			return this._position;
		}
		
		public function set type(v:String){
			this._type=v;
		}
		
		public function get type():String{
			return this._type;
		}
		
		public function set patternType(v:String){
			this._patternType=v;
		}
		
		public function get patternType():String{
			return this._patternType;
		}
				
		public function set inputTran(v:TranFigure){
			this._inputTran=v;
		}
		
		public function get inputTran():TranFigure{
			return this._inputTran;
		}
		
		public function set outputTran(v:TranFigure){
			this._outputTran=v;
		}
		
		public function get outputTran():TranFigure{
			return this._outputTran;
		}
		
		public function initContextMenu(){
					
			this.contextMenu= new ContextMenu();
			this.contextMenu.hideBuiltInItems();
			
			
			initSendItem = new ContextMenuItem("触发初始请求事件");
			sendItem = new ContextMenuItem("触发响应事件");
			initReceiveItem = new ContextMenuItem("监听初始请求事件");
			receiveItem = new ContextMenuItem("监听响应事件");
			
			initSendItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, initSendDispose);
			sendItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, sendDispose);
			initReceiveItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, initReceiveDispose);
			receiveItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, receiveDispose);
			if(_type=="etr"){
				this.contextMenu.customItems.push(initSendItem);
				this.contextMenu.customItems.push(sendItem);
			}else{
				this.contextMenu.customItems.push(initReceiveItem);
				this.contextMenu.customItems.push(receiveItem);
			}
		
		}
		
		public function initSendDispose(event:Event){
			this.graphics.lineStyle(2,0x000000);
			this.graphics.drawRect(3,3,width-6,height-6);
			this.graphics.drawRect(6,6,width-12,height-12);
			this.label="S:E";
			this._patternType="initSend";
		}
		
		public function sendDispose(event:Event){
			this.label="S:E";
			this._patternType="Send";
		}
		
		public function initReceiveDispose(event:Event){
			this.graphics.lineStyle(2,0x000000);
			this.graphics.drawRect(3,3,width-6,height-6);
			this.graphics.drawRect(6,6,width-12,height-12);
			this.label="R:E";
			this._patternType="initReceive";
		}
		
		public function receiveDispose(event:Event){
			this.label="R:E";
			this._patternType="Receive";
		}
			

	}
}